home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
bbsutil
/
bsrc_250.zip
/
ASYNC.C
next >
Wrap
C/C++ Source or Header
|
1991-09-15
|
21KB
|
714 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software, Co. */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / Freely Available<tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
/* */
/* */
/* This module was written by Peter Fitzsimmons */
/* */
/* */
/* BinkleyTerm OS/2 Async Comm I/O Routines */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.250. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT BIT BUCKET */
/* SOFTWARE CO. AT ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT */
/* SHOULD YOU PROCEED TO USE THIS FILE WITHOUT HAVING ACCEPTED THE */
/* TERMS OF THE BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER */
/* AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO. */
/* */
/* */
/* You can contact Bit Bucket Software Co. at any one of the following */
/* addresses: */
/* */
/* Bit Bucket Software Co. FidoNet 1:104/501, 1:343/491 */
/* P.O. Box 460398 AlterNet 7:491/0 */
/* Aurora, CO 80046 BBS-Net 86:2030/1 */
gg/* Internet f491.n343.z1.fidonet.org */
/* */
/* Please feel free to contact us at any time to share your comments about */
/* our software and/or licensing policies. */
/* */
/*--------------------------------------------------------------------------*/
#ifndef OS_2
#pragma message("This Module For OS/2")
#else
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#define INCL_DOS
#define INCL_DOSDEVICES
#define INCL_DOSDEVIOCTL
#define INCL_DOSSEMAPHORES
#define INCL_NOPM
#include <os2.h>
#include "bink.h"
#include "com.h"
#include "async.h"
/*--------------------------------------------------------*
* This file contains the operating system specific *
* serial communications routines for OS/2. *
* *
* (C) Copyright Peter Fitzsimmons Sun 04-16-1989 *
* *
* Add-ins for BinkleyTerm on Sat 05-06-1989 *
* *
* Worked over once again on 06/06-91, trying to get the *
* same effect as the Rev 6 FOSSIL in it *
*--------------------------------------------------------*/
/* This one has excellent send or receive, even with 8088 */
/* but the xmit rate is a bit low in Janus w/o SetPrty. */
/* #define DEBUG */ /* Exposes a bit more about ASYNC comm */
/* #define MultiWrt */ /* Not always reliable */
extern void status_line (char *,...);
extern void com_kick (void);
/* Private data */
/* static HFILE hfComHandle = -1; */ /* handle from DosOpen() */
HFILE hfComHandle = -1; /* handle from DosOpen() */
/* transmitter stuff */
#define TSIZE 8192
static unsigned char tBuf[TSIZE];
static unsigned char zTxBuf[TSIZE];
static int zpos = 0;
static int tBufsize = 0;
static unsigned int TQSize = 0;
/* static HSEM WriteSem = 0; */
ULONG WriteSem = 0;
/* receiver stuff */
#define RSIZE 8192
static unsigned char rbuf[RSIZE];
static USHORT rpos = 0;
static int rbufsize = 0;
static USHORT Rbytes = 0;
static word RQBbytes = 0;
static word RQBbyte2 = 0;
#ifdef DEBUG
#define debug_msg(m,c) status_line("!" m, c)
#define IOCtl(func, data, parm) _ioctl(#func, func, (void far *) data, (void far *) parm)
static int _ioctl(char *funcname, int func, void far * data, void far * parm)
{
int i;
if (i = DosDevIOCtl((PVOID) data, (PVOID) parm, func, IOCTL_ASYNC, (HFILE) hfComHandle)) {
printf("ioctl(%s) err(0x%04x)\n", funcname, i);
status_line("!ioctl(%s) err(0x%04x)", funcname, i);
}
return (i);
}
#else
#define debug_msg(m,c)
#define IOCtl(func, data, parm) DosDevIOCtl((PVOID) data, (PVOID) parm, func, IOCTL_ASYNC, (HFILE) hfComHandle)
#endif
static int com_getDCB(struct _DCBINFO far * dcb);
static int com_setDCB(struct _DCBINFO far * dcb);
/* com_init() : Intialize communications port. Baud rate is preserved.
* int port : Hardware port (0 based) to init
* -OR- char *unc : Full UNC \\networkId\modemId to init.
*
* if unc==NULL, port is used. if unc != NULL, unc is used
*/
int com_init(int port, char far *unc)
{
char str[30];
char *s;
USHORT ActionTaken; /* action: returned by OS/2 */
USHORT stat;
DCBINFO sDCB;
RXQUEUE q;
cputs("\033[1;33mOS/2 FOSSIL emulator for BinkleyTerm, Peter Fitzsimmons (1:250/628)\033[0m\r\n");
sprintf(str, "COM%d", port + 1);
if (!unc)
unc = str;
#ifdef DEBUG
stat = DosOpen((PSZ) unc,(PHFILE) &hfComHandle,(PUSHORT) &ActionTaken, 0L, 0, 0x0001, 0x4012, 0L);
#else
stat = DosOpen((PSZ) unc,(PHFILE) &hfComHandle,(PUSHORT) &ActionTaken, 0L, 0, 0x0001, 0x6012, 0L);
#endif
if (stat) {
hfComHandle = -1;
printf("com_init() : DosOpen() error 0x%04x on '%s'\n", stat, unc);
return (FALSE);
}
(void) DosSemClear((HSEM) &WriteSem);
if (!IOCtl(ASYNC_GETINQUECOUNT, (PVOID) &q, (PVOID) 0L)) {
s = getenv("RBUF");
if (s)
rbufsize = min( RSIZE, atoi(s));
else
rbufsize = RSIZE;
RQBbytes = min( RSIZE, rbufsize);
RQBbyte2 = RQBbytes/2;
#ifdef DEBUG
printf("com_init() : ASYNC Input Buffer size is %d'\n", q.cb);
#endif
}
if (!IOCtl(ASYNC_GETOUTQUECOUNT, (PVOID) &q, (PVOID) 0L)) {
s = getenv("TBUF");
if (s)
tBufsize = min( TSIZE, atoi(s));
else
tBufsize = TSIZE;
/* TQSize = min(TSIZE, q.cb/2); */ /* WRA */
TQSize = min(TSIZE, q.cb-16);
#ifdef DEBUG
printf("com_init() : ASYNC Output Buffer size is %d'\n", q.cb);
#endif
}
com_XON_disable();
com_getDCB((struct _DCBINFO far *) &sDCB);